package com.neuedu.service.Imp;

import com.neuedu.dao.EmployeeDao;
import com.neuedu.dao.Imp.EmployeeDaoImp;
import com.neuedu.pojo.Employee;
import com.neuedu.pojo.PageResult;
import com.neuedu.service.EmployeeService;

import java.util.List;

public class EmployeeServiceImp implements EmployeeService {
    private EmployeeDao employeeDao = new EmployeeDaoImp();
    @Override
    public List<Employee> getEmpAll(){
        try{
            return employeeDao.getEmpAll();
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Integer addEmp(String account,String password,String nickname,String telephone,String role,int isDel) {
        try{
            return employeeDao.addEmp(account,password,nickname,telephone,role,isDel);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Integer delEmp(String id) {
        try{
            return employeeDao.delEmp(id);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Integer updateEmp(String id, String account, String password, String nickname, String telephone, String role, String isDel) {
        try{
            return employeeDao.update(id,account,password,nickname,telephone,role,isDel);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Employee selectPart(String account, String password) {
        try{
            return employeeDao.selectPar(account,password);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public PageResult<List<Employee>> getEmp(String currentPage, String pageSize, String account, String nickname, String telephone) {
        try{
            List<Employee> emp = employeeDao.getEmp(currentPage, pageSize, account, nickname, telephone);
            Long l = employeeDao.countEmp();
            PageResult<List<Employee>> pageResult = new PageResult<>();
            pageResult.setTotal(l);
            pageResult.setDatas(emp);
            return pageResult;
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
}
